﻿using FSharp.Windows;
using System.Windows;
using System.Diagnostics;
using Microsoft.VisualBasic.Logging;
using System;

namespace Warehouse
{
    public partial class Program : Application
    {
        public Program()
        {
            var mainWindow = new Controls.MainWindow { Visibility = Visibility.Visible };
            this.MainWindow = mainWindow;
            var mvc = MainController.Mvc(mainWindow);
            this.AttachMvc(mvc);

            //this.Startup += delegate
            //{
            //    var mainWindow = new Controls.MainWindow { Visibility = Visibility.Visible };
            //    this.MainWindow = mainWindow;
            //    var mvc = MainController.Mvc(mainWindow);
            //    mvc.Start();
            //    Debug.WriteLine("Started ...");
            //};
            Trace.Listeners.Clear();
#if DEBUG
            Trace.Listeners.Add(new DefaultTraceListener());
#endif
            Trace.Listeners.Add(new FileLogTraceListener
            {
                BaseFileName = Process.GetCurrentProcess().ProcessName,
                LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly,
                TraceOutputOptions = TraceOptions.DateTime,
                MaxFileSize = long.MaxValue,
                AutoFlush = true,
            });
            this.DispatcherUnhandledException += (_, args) =>
            {
                var why = args.Exception;
                if (why is TypeInitializationException) why = why.InnerException;
                MessageBox.Show(why.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                Trace.WriteLine(why);
                args.Handled = true;
            };
        }
    }
}
